package com.myqf2.d10_dbutils_xml.dbutils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
/*
通过druid连接池 获取连接 并返回
 */
public class druid连接池获取连接 {
    //声明连接池对象
    private static DruidDataSource ds;
    static{

        //实例化配置对象
        Properties properties=new Properties();
        try {
            InputStream is = druid连接池获取连接.class.getClassLoader().getResourceAsStream("myqf2_d10.properties");
            //加载配置文件内容
            properties.load(is);
            ds = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    //获取连接对象
    public static Connection getConnection() {
        try {
            return ds.getConnection();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
    //关闭资源的方法
    public static void close(Connection con, PreparedStatement pre, ResultSet rs){

    }
}
